package com.damon.utils;

import java.io.File;
import java.util.LinkedList;

public class FilesUtil {
	
	public static void traverseFileByLinked(String path){
	    File[] files;
	    File file=new File(path);
	    if(file.exists()){
	        LinkedList<File> list=new LinkedList<File>();
	        list.add(file);
	        while(!list.isEmpty()){
	            File file2=list.removeFirst();
	            files=file2.listFiles();
	            for(File f:files){
	                if(f.isDirectory()){
	                    System.out.println("文件夹："+f.getAbsolutePath());
	                    list.add(f);
	                }else{
	                    System.out.println("文件："+f.getAbsolutePath());
	                }
	            }
	        }
	        
	    }else{
	        System.out.println("文件不存在！");
	    }
	}
	
	public static void traverseFileByRecursion(String path){
	    File file=new File(path);
	    if(file.exists()){
	        File[] f=file.listFiles();
	        for(File files:f){
	            if(files.isDirectory()){
	                System.out.println("文件夹："+files.getAbsolutePath());
	                traverseFileByRecursion(files.getAbsolutePath());
	            }else{
	                System.out.println("文件："+files.getAbsolutePath());
	            }
	        }
	    }else{
	        System.out.println("文件不存在！");
	    }
	}
}
